package com.ayf.payment.game.api.service.platform.impl;

import com.ayf.payment.game.api.dto.platform.MerchantSettleRateConfigDTO;
import com.ayf.payment.game.api.entity.platform.MerchantSettleRateConfig;
import com.ayf.payment.game.api.mapper.platform.MerchantSettleRateConfigMapper;
import com.ayf.payment.game.api.service.platform.MerchantSettleRateConfigService;
import com.swwx.charm.commons.lang.utils.BeanConvertUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MerchantSettleRateConfigServiceImpl implements MerchantSettleRateConfigService {

    @Resource
    private MerchantSettleRateConfigMapper merchantSettleRateConfigMapper;


    @Override
    public void insertMerchantSettleRateConfigs(List<MerchantSettleRateConfigDTO> list, Integer rateId) {
        merchantSettleRateConfigMapper.inserts(list,rateId);
    }

    @Override
    public void delMerchantSettleRateConfigs(Integer rateId) {
        Example example = new Example(MerchantSettleRateConfig.class);
        example.createCriteria().andEqualTo("rateId",rateId);
        merchantSettleRateConfigMapper.deleteByExample(example);
    }

    @Override
    public void updateMerchantSettleRateConfig(MerchantSettleRateConfigDTO merchantSettleRateConfigDTO) {
        merchantSettleRateConfigMapper.updateMerchantAccount(merchantSettleRateConfigDTO);
    }

    /**
     *
     * @author lch
     * @date 2022/3/7
     */
	@Override
	public MerchantSettleRateConfigDTO getById(Integer id) {
		MerchantSettleRateConfig merchantSettleRateConfig = this.merchantSettleRateConfigMapper.selectByPrimaryKey(id);
		return BeanConvertUtils.convert(merchantSettleRateConfig, MerchantSettleRateConfigDTO.class);
	}

	/**
	 * 根据产品id获取
	 * @author lch
	 * @date 2022/3/7
	 */
	@Override
	public MerchantSettleRateConfigDTO getByPayProductId(Integer payProductId) {
		Example example = new Example(MerchantSettleRateConfig.class);
		example.createCriteria().andEqualTo(MerchantSettleRateConfig.Fields.payProductId, payProductId);
		MerchantSettleRateConfig merchantSettleRateConfig = this.merchantSettleRateConfigMapper.selectOneByExample(example);
		return BeanConvertUtils.convert(merchantSettleRateConfig, MerchantSettleRateConfigDTO.class);
	}
}
